package gui.common;

import gui.common.msg.MsgType;
import gui.common.msg.SysMessage;

import javax.swing.JFrame;
import javax.swing.JPanel;



import client.DataClient;

public abstract class BaseClientFrame extends JFrame{

	private static final long serialVersionUID = 1L;
	
	protected DataClient dataClinet = null;
	
	private JPanel content=null;
	
	private boolean isConnected=false;
	
	
	public boolean isConnected() {
		return isConnected;
	}

	public void setConnected(boolean isConnected) {
		this.isConnected = isConnected;
	}

	public BaseClientFrame(String  name){
		super(name);
		try{
			dataClinet=new DataClient();
			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public final DataClient getDataClient() {
		return dataClinet;
	}
	public final void setContent(JPanel panel){
		if(panel!=null){
			if(content!=null){
				this.remove(content);
			}
			this.add(panel);
			this.validate();
			
			content=panel;
			
		}else{
			System.err.println("cant not set content");
		}
		
	}
	public final JPanel getContent() {
		return content;
	}
	public final SysMessage connectServer(){
		SysMessage msg=new SysMessage();
		msg.subject="Connect Server";
		try {
			dataClinet=new DataClient();
			dataClinet.connectServer();
			
			msg.type=MsgType.Success;
			msg.detail="Connect Successed:";
			isConnected=true;
		} catch (Exception e) {
			e.printStackTrace();
			msg.type=MsgType.Success;
			msg.detail=e.getMessage();
		}
		return msg;
	}
	
	

}
